package models;

import views.TurretInterfaceView;
import controllers.ByteHandler;
import controllers.MoveStepperMotorThread;
import controllers.SerialTurret;
import gnu.io.SerialPort;

public class StepperMotor {

	private int currentPosition;
	private Thread moveThread;
	
	public StepperMotor() {
		this.currentPosition = 0;
	}
	
	public void move_to_pos(int pos) throws InterruptedException {
		if(Math.abs(pos-currentPosition)>240) {
			System.err.println("Can't move that far in one step!");
		} else {
			moveThread = new Thread(new MoveStepperMotorThread(ByteHandler.createStepperMotorBytes(pos-currentPosition)));
			moveThread.start();
			currentPosition = pos;
			TurretInterfaceView.stepperMotorPositionLabel.setText(Integer.toString(currentPosition));	
		}
	}

	public int getCurrentPosition() {
		return currentPosition;
	}
	
}